package com.wang.tank;

/**
 * @author 王先锋
 * @version 1.0
 */
public class Shot extends Thread {
    private int x;
    private int y;
    private int direct = 0;
    private int speed = 2;
    boolean isLive = true;//子弹是否存活

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
    }

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            switch (direct) {
                case 0:
                    y -= speed;
                    break;
                case 1:
                    x += speed;
                    break;
                case 2:
                    y += speed;
                    break;
                case 3:
                    x -= speed;
                    break;
            }//测试
            System.out.println(x+y);
            //当子弹移动到面板边界时，应该销毁
            //当子弹碰到敌人坦克时应该销毁
            if(!(x>=0&&x<1000 && y>=0 && y<=750 && isLive)){
               isLive=false;
               break;
            }
        }
    }
}
